﻿using System;
using System.Data;
using System.Collections.Generic;
using ZHDJ.MobileInterface.Common;
using SXT.Data;

namespace ZHDJ.MobileInterface
{
    public partial class ToAddLawCallMassage : AbstractBasePage
    {
        protected override OutParam BusinessProcess<InParam, OutParam>(InParam inParam)
        {
            // 业务逻辑返回的响应对象  
            AddLawCallMassageOutParam result = new AddLawCallMassageOutParam();
            AddLawCallMassageInParam param = new AddLawCallMassageInParam();
            string logMsg = "";
            bool isFlag = true;

            try
            {
                param = inParam as AddLawCallMassageInParam;

                if (string.IsNullOrEmpty(param.LoginID)||string.IsNullOrEmpty(param.UserName)||string.IsNullOrEmpty(param.PhoneNo))
                {
                    result.code = "0";
                    result.desc = "用户ID、用户名字、用户电话不能为空";

                    isFlag = false;
                }
                if(isFlag)
                 {
                     string rfResult = InsertData(param.LoginID, param.UserName, param.PhoneNo);
                    if (!string.IsNullOrEmpty(rfResult))
                    {
                        result.code = "0";
                        result.desc = rfResult;

                        isFlag = false;
                    }
                 }
                logMsg = result.desc;
            }
            catch (Exception ex)
            {
                result.code = "0";
                result.desc = "转移过程出现异常，多次出现请联系管理员";
                logMsg = ex.Message + ":" + ex.StackTrace;
            }

            CommonUtils.InsertMobileInterfaceLog(SystemCode + "-ToAddLawCallMassage", SerializeHelper.JsonSerializer<AddLawCallMassageInParam>(param), logMsg);
            return result as OutParam;
        }

        protected void Page_Load(object sender, System.EventArgs e)
        {
            if (string.Compare(Request.QueryString["Safe"], "False", true) == 0)
                ProcessRequest<AddLawCallMassageInParam, AddLawCallMassageOutParam>();
            else
                SafeProcessRequest<AddLawCallMassageInParam, AddLawCallMassageOutParam>();
        }

        private static string InsertData(string LoginID,string UserName,string PhoneNo)
        {
            bool IsOK=true;
            using (System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand())
            {
                string sql = string.Format(@" insert into tblLawCallMassage values('{0}','{1}','{2}','{3}','{4}')",
                    StringHelper.NewID, LoginID, UserName, PhoneNo, DateTime.Now);
                cmd.CommandText = sql;
                try
                {
                    IsOK=SXT.DB.DBManager.DBSettings["SXT.DefaultDBEx"].ExecuteNonQuery(cmd) >= 0;
                }
                catch (Exception)
                {
                    
                    IsOK=false;
                }
                if (IsOK)
                { return ""; }
                else return "数据插入失败！";
            }
        }
    }

    #region 请求参数
    public class AddLawCallMassageInParam
    {
        /// <summary>
        /// 登录ID
        /// </summary>
        public string LoginID { get; set; }

        /// <summary>
        /// 律师
        /// </summary>
        public string UserName { get; set; }

        /// <summary>
        /// 咨询人
        /// </summary>
        public string PhoneNo { get; set; }




    }
    #endregion

    #region 结果参数
    public class AddLawCallMassageOutParam
    {
        public AddLawCallMassageOutParam()
        {
            code = "1";
            desc = "操作成功";
        }

        /// <summary>
        /// 返回结果 具体见接口返回对照码 1	成功 0	失败 2	请求非法 加密结果和传入的MD5字符串进行比较，如果相同则执行接口操作，否则返回1001错误响应码
        /// </summary>
        public string code
        { get; set; }

        /// <summary>
        /// 结果描述 成功和失败都需要
        /// </summary>
        public string desc
        { get; set; }
    }
    #endregion

}